package com.yc.web.servlets.admin;

import com.yc.bean.Menu;
import com.yc.web.servlets.BaseServlet;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zwei
 * @create 2024-06-19 18:49
 */
@WebServlet("/admin/menu.action")
public class MenuServlet extends BaseServlet {
    public void getMyMenu(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //访问业务层  得到当前用户  取得他的菜单拼接成结果
        List<Menu>menuList=new ArrayList<>();
        Menu m=new Menu();
        List<Menu>sonList=new ArrayList<>();

        //子列表
        Menu sonMenu=new Menu();
        sonMenu.setTitle("用户列表");
        sonMenu.setHref("pages/member/user-list.html");
        sonMenu.setFontFamily("layui-icon");
        sonMenu.setIcon("&#xe62e;");
        sonMenu.setSpread(false);

        Menu sonMenu2=new Menu();
        sonMenu2.setTitle("菜单列表");
        sonMenu2.setHref("pages/member/food-list.html");
        sonMenu2.setFontFamily("layui-icon");
        sonMenu2.setIcon("&#xe62e;");
        sonMenu2.setSpread(false);

        Menu sonMenu3=new Menu();
        sonMenu3.setTitle("订单列表");
        sonMenu3.setHref("pages/member/order-list.html");
        sonMenu3.setFontFamily("layui-icon");
        sonMenu3.setIcon("&#xe62e;");
        sonMenu3.setSpread(false);

        //将子列表添加到子集合中
        sonList.add(sonMenu);
        sonList.add(sonMenu2);
        sonList.add(sonMenu3);
        m.setTitle("会员管理");
        m.setHref("");
        m.setIcon("&#xe66f;");
        m.setSpread(false);
        m.setChildren(sonList);     //将子集合存到父列表中
        menuList.add(m);
        super.writeObjectToJson(menuList,resp);

    }
}
